package com.yikome.shop.service;

import cn.hutool.core.util.StrUtil;

public class StrHideUtils {

	public static String hideStr(String content, int begin, int end) {
		
		if (begin >= content.length() || begin < 0) {
			return content;
		}
		if (end > content.length() || end < 0) {
			return content;
		}
		if (begin >= end) {
			return content;
		}
		String starStr = "";
		for (int i = begin; i < end; i++) {
			starStr = starStr + "*";
		}
		return content.substring(0, begin) + starStr + content.substring(end, content.length());
	}
	
	public static String hideStr(String content) {
		
		content = StrUtil.trim(content);
		
		if(content.length() == 0 || content.length() == 1) return content;
		
		if(content.length() == 2 || content.length() == 3) return hideStr(content, 1, 2) ; 
		
		if(content.length() == 4 || content.length() == 5 || content.length() == 6) return hideStr(content, 1, content.length() - 1) ; 
		
		if(content.length() >= 7) return hideStr(content, content.length()/2 - 2, content.length()/2 + 2) ; 
		
		return content;
	}
}
